package com.{{.PackageName}}.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.bizcore.web.support.Searchable;
import {{.PackageName}}.dto.{{.ClassName}}DTO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "{{.TableComment}}管理")
@RestController
@RequestMapping(value = "/api/w/{{.LowerClassName}}")
public class {{.ClassName}}Controller {

    @Autowired
    private {{.ClassName}}Service {{.LowerClassName}}Service;


    @ApiOperation("查询所有{{.TableComment}}")
    @GetMapping
    public ResultListDTO<{{.ClassName}}DTO> index(final Searchable searchable) {
        final List<{{.ClassName}}DTO> DTOs = this.{{.LowerClassName}}Service.findAll(searchable);
        final ResultListDTO<{{.ClassName}}DTO> result = ResultListDTO.success(DTOs);
        return result;
    }

    @ApiOperation("分页查询所有{{.TableComment}}")
    @GetMapping("/p")
    public PageResultDTO<{{.ClassName}}DTO> search(final Pageable pageable, final Searchable searchable) {
        return PageResultDTO.success(this.{{.LowerClassName}}Service.search(pageable, searchable));
    }

    @ApiOperation("创建{{.TableComment}}")
    @PostMapping("")
    public ResultDTO<{{.ClassName}}DTO> create(@RequestBody final {{.ClassName}}DTO dto) {
        final {{.ClassName}}DTO result = this.{{.LowerClassName}}Service.create(dto);
        return ResultDTO.success(result);
    }

    @ApiOperation(value = "修改{{.TableComment}}")
    @PutMapping("/{id}")
    public ResultDTO<{{.ClassName}}DTO> update(@PathVariable final Long id,
            @RequestBody final {{.ClassName}}DTO dto) {
        final {{.ClassName}}DTO result = this.{{.LowerClassName}}Service.update(id, dto);
        return ResultDTO.success(result);
    }

    @ApiOperation("{{.TableComment}}详情")
    @GetMapping("/{id}")
    public ResultDTO<{{.ClassName}}DTO> details(@PathVariable final Long id) {
        final {{.ClassName}}DTO dto = this.{{.LowerClassName}}Service.details(id);
        return ResultDTO.success(dto);
    }

    @ApiOperation("删除{{.TableComment}}")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id) {
        this.{{.ClassName}}Service.delete(id);
        return ResultDTO.success();
    }
}